package cz.muni.fi.pa165.web;

import cz.muni.dto.ShipmentDTO;
import cz.muni.service.ShipmentServiceLocal;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

/**
 *
 * @author OSiRiS-PC
 */
@UrlBinding("/Customer.{$event}")
public class CustomerActionBean implements ActionBean {

    @EJB(mappedName = "java:global/DeliveryCompany-web/ShipmentService!cz.muni.service.ShipmentServiceLocal")
    public ShipmentServiceLocal shipmentService;
    private ShipmentDTO shipment;
    private ActionBeanContext context;

    public ShipmentDTO getShipment() {
        return shipment;
    }

    public void setShipment(ShipmentDTO shipment) {
        this.shipment = shipment;
    }
    @DefaultHandler
    public Resolution searchorder() {
        return new ForwardResolution("/searchorder.jsp");
    }

    // SOME BUGS MAYBE HERE
    public List<ShipmentDTO> getTrackedShipment() {
        List<ShipmentDTO> list = new ArrayList();
        try {
            Long tn = shipment.getTrackingNumber();
            System.out.println(tn.toString());
            ShipmentDTO shipmentDTO = shipmentService.findByTrackingNumber(tn);
            System.out.println(shipmentDTO);
            
            list.add(shipmentDTO);
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        }
        return list;
    }

    @Override
    public void setContext(ActionBeanContext abc) {
        this.context = abc;
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }
}
